package com.colorful.insuranceproject.request;

import android.os.Handler;

import com.colorful.insuranceproject.bean.BankCardBean;
import com.colorful.insuranceproject.bean.DeliveryBean;
import com.colorful.insuranceproject.bean.PersonInfoBean;
import com.colorful.insuranceproject.consts.URLConst;
import com.lovely3x.common.requests.impl.HandlerRequestImpl;
import com.lovely3x.common.utils.ALog;
import com.lovely3x.common.utils.Response;
import com.lovely3x.jsonparser.model.JSONObject;

/**
 * Created by handsome-Bob on 2017/8/15.
 * <p>
 * 个人板块的请求页面
 */
public class MineRequest extends BaseRequest {
    public MineRequest(Handler handler) {
        super(handler);
    }

    /**
     * 获取个人信息
     *
     * @param what handler传递值
     */
    public void getUserInfoUrl(int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取个人信息-----------------》" + result);
                    res.obj = result.getJSONObject(DATA_KEY).createObject(PersonInfoBean.class);
                }
            }
        }, URLConst.GET_USER_INFO_URL, what);
    }

    /**
     * 获取银行卡列表
     *
     * @param what handler传递值
     */
    public void getBankCardList(int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取银行卡列表-----------------》" + result);
                    res.obj = result.getJSONArray(DATA_KEY).createObjects(BankCardBean.class);
                }
            }
        }, URLConst.GET_BANK_CARD_LIST_URL, what);
    }

    /**
     * 认证银行卡
     *
     * @param realName    真实姓名
     * @param idCardNum   身份证号
     * @param bankCardNum 银行卡号
     * @param name        开户银行
     * @param phone       预留手机号
     * @param what        handler传递值
     */
    public void authenticationBankCardUrl(String realName, String idCardNum, String bankCardNum, String name, String phone, int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.AUTHENTICATION_BANK_CARD_URL_TWO, what, "userName", realName,
                "idCard", idCardNum, "cardNumber", bankCardNum, "bankPhone", phone);
    }

    /**
     * 添加银行卡
     *
     * @param realName    真实姓名
     * @param idCardNum   身份证号
     * @param bankCardNum 银行卡号
     * @param name        开户银行
     * @param phone       预留手机号
     * @param what        handler传递值
     */
    public void addBankCardUrl(String realName, String idCardNum, String bankCardNum, String name, String phone, int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.ADD_BANK_CARD_URL, what, "userName", realName, "idCard", idCardNum,
                "cardNumber", bankCardNum, "bankPhone", phone, "bankName", name);
    }

    /**
     * 获取收货地址
     *
     * @param what handler传递值
     */
    public void getDeliverUrl(int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取收货地址-----------------》" + result);
                    res.obj = result.getJSONArray(DATA_KEY).createObjects(DeliveryBean.class);
                }
            }
        }, URLConst.GET_DELIVER_INFO_URL, what);
    }

    /**
     * 编辑或者添加收货地址
     *
     * @param addressId   地址的ID
     * @param userName    收货人姓名
     * @param areaId      地区ID
     * @param userPhone   电话号码
     * @param userAddress 用户收获地址
     * @param isDefault   是否为默认的收获地址
     * @param what        handler 传递值
     */
    public void addNewShoppingAddress(String addressId, String userName, String areaId, String userPhone, String userAddress, int isDefault, String post, int what) {
        process(new ProcessResult() {
                    @Override
                    public void onResult(Response res, JSONObject result) throws Exception {
                        if (res.isSuccessful) {
                            ALog.e(TAG, "编辑或者添加收货地址------------>" + result);
                        }
                    }
                }, URLConst.ADD_NEW_SHOPPING_ADDRESS, what, "lastAreaId", areaId, "userName", userName, "areaId", areaId,
                "userPhone", userPhone, "address", userAddress, "isDefault", isDefault, "post", post, "addressId", addressId);
    }

    /**
     * 绑定银行卡的认证
     *
     * @param what handler
     */
    public void bindBankCardAuthentication(int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.BIND_BANK_CARD_AUTHENTICATION, what);
    }

    /**
     * 删除银行卡
     *
     * @param listDelete 银行卡号的数据
     * @param what       handler
     */
    public void deleteBankCard(String listDelete, int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.DELETE_BANK_CARD, what, "cardNumbers", listDelete);
    }

    /**
     * 删除收货地址
     *
     * @param addressId id
     * @param what      handler
     */
    public void deleteDelivery(String addressId, int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.DELETE_DELIVERY_URL, what, "userAddressIds", addressId);
    }

    /**
     * 设置默认收货地址
     *
     * @param addressId id
     * @param what      handler
     */
    public void setDefaultDelivery(String addressId, int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.SET_DEFAULT_DELIVERY_URL, what, "userAddressId", addressId);
    }

    /**
     * 实名认证
     *
     * @param s    name
     * @param s1   card
     * @param what handler
     */
    public void realNameAuthentication(String s, String s1, int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.REAL_NAME_AUTHENTICATION, what, "idName", s, "idNo", s1);
    }

    public void textTransportSuccess(String s, String s1, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "查看推送至------------------>" + result);
                }
            }
        }, URLConst.TEXT_TRANSPORT, what, "msgType", s, "state", s1);
    }
}
